Skip to contents

To illustrate how interactive plots work in ebm, we’ll fit a simple EBM regression model to the Hitters data from the ISLR2 package.

library(ebm)

# Load the data and remove rows with missing response values
data("Hitters", package = "ISLR2")
hitters <- Hitters[!is.na(Hitters$Salary), ]

# Fit a simple EBM; here we turn off some of the more expensive arguments
fit <- ebm(Salary ~ ., data = hitters, objective = "rmse", inner_bags = 0,
           outer_bags = 1, interactions = 0)

You can produce several plotly-based graphs to help interpret the output of "EBM" objects by calling the generic plot() method with interactive = TRUE; this function supports both global and local interpretations. The default simply prints a global measure of importance based on the mean absolute score for each term. (For Markdown-type documents, like this article, you also need to specify display = "markdown"; see ?ebm::plot for details.)

# Plot feature importance (i.e., mean absolute scores)
plot(fit, interactive = TRUE, display = "markdown")

You can also plot the individual shape functions (or term contributions), as shown below:

plot(fit, term = "Years", interactive = TRUE, display = "markdown")

You can also display local explanations (though, one at a time) by specifying local = TRUE:

# Understand an individual prediction
x <- subset(hitters, select = -Salary)[1L, ]  # use first observation
plot(fit, local = TRUE, X = x, y = hitters$Salary[1L], 
     interactive = TRUE, display = "markdown")